package com.hua.nailcampus.acl.controller;

import com.hua.nailcampus.acl.model.Province;
import com.hua.nailcampus.acl.model.vo.ProvinceCityVo;
import com.hua.nailcampus.acl.service.ProvinceService;
import com.hua.nailcampus.constant.RedisConst;
import com.hua.nailcampus.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author:chenjianhua
 * @Date:2023/11/22 22:50
 * @Version 1.8
 */
@RestController
@RequestMapping("nailCampus/province")
@CrossOrigin
public class ProvinceController {

    @Autowired
    private ProvinceService provinceService;

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 获取所有省份以及城市
     * @return
     */
    @GetMapping("/getAllProvince")
    public Result getAllProvince(){
        List<ProvinceCityVo> provinceCityVoList = (List<ProvinceCityVo>) redisTemplate.opsForValue().get(RedisConst.PROVINCE_LISTK);
        if(provinceCityVoList==null){
            provinceCityVoList = provinceService.getAllProvince();
        }
       return Result.ok(provinceCityVoList);
    }
}
